home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2007 July & August
/
PCWorld_2007-07-08_cd.bin
/
komunikace
/
ie7pro
/
IE7proSetup.exe
/
{app}
/
plugins
/
accuweather
/
js
/
findLocation.js
Wrap
Text File
|
2007-03-20
|
3KB
|
93 lines
//initialize the findLocation window
function init() {
var currentSetting=PRO_getValue("weather_Location","");
if (currentSetting!="") {
PRO_log(currentSetting)
arr = currentSetting.split("|");
if(arr[3])
envVar.innerText=arr[3];
else
envVar.innerText=currentSetting;
}
var currentUnit=PRO_getValue("weather_Unit","");
if (currentUnit!="english") {
metric.checked = true;
}else{
english.checked = true;
}
}
//load the xml data from the website
function loadData() {
req = PRO_xmlhttpRequest();
if (req) {
req.open("GET","http://vwidget.accuweather.com/widget/vista1/locate_city.asp?location=" + envVar.value,true);
req.onreadystatechange=processData;
req.send();
}
}
//process data when its received
function processData() {
if (req.readyState==4) {
if (req.status==200) {
parseData(req.responseXML.documentElement);
}
}
}
//parse the xml data and populate the table with data.
function parseData(xmlData) {
tempNode=xmlData.getElementsByTagName("./citylist").item(0);
tempNodes=tempNode.getElementsByTagName('location');
deleteRows("LocationTable");
for (count=0;count<tempNodes.length;count++) {
cityNode=tempNodes[count];
tempString="<a class=\"link\" href=\"#\" onClick=\"selectLocation('" + cityNode.getAttribute("location") + "');return false;\">+</a> ";
tempString1="<a class=\"link\" href=\"#\" onClick=\"selectLocation('" + cityNode.getAttribute("location") + "');return false;\">" + cityNode.getAttribute("city") + ", " + cityNode.getAttribute("state") + "</a>";
addRow("LocationTable",tempString,tempString1);
}
if (tempNodes.length==0) {
addRow("LocationTable","Location not found","");
}
with (scrollTableContainer.style) {
display="block";
}
}
//add a row programatically to a table
function addRow(id,value,text){
var tbody=document.getElementById(id).getElementsByTagName("tbody")[0];
var row=document.createElement("TR");
var cell1=document.createElement("TD");
cell1.innerHTML=value;
cell1.style.whiteSpace="nowrap";
var cell2=document.createElement("TD");
cell2.innerHTML=text;
cell2.style.whiteSpace="nowrap";
row.appendChild(cell1);
row.appendChild(cell2);
tbody.appendChild(row);
}
//delete a row from a table
function deleteRows(id) {
var tbl=document.getElementById(id);
totalRows=tbl.rows.length;
for (count=0;count<totalRows;count++) {
document.getElementById(id).deleteRow(0);
}
}
//if a location is selected save it to the settings and close the flyout
function selectLocation(locationCode) {
PRO_setValue("weather_Location",locationCode);
alert("Location Selected. \rNow We will close config window.");
window.close();
}
function selectUnit(Unit) {
PRO_setValue("weather_Unit",Unit);
PRO_log("set weather_Unit " + Unit)
//alert("Unit Selected. ");
}